import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 当前登录用户信息
    user: JSON.parse(window.localStorage.getItem('user') || 'null'),
    // 收缩状态
    collapseSideMenu: false,
    // 标题
    title: ''
  },
  mutations: {
    setUser (state, payload) {
      if (typeof payload === 'string') {
        state.user = JSON.parse(payload)
      } else {
        state.user = payload
        payload = JSON.stringify(payload)
      }
      window.localStorage.setItem('user', payload)
    },
    setCollapseSideMenu (state, payload) {
      state.collapseSideMenu = payload
    },
    setTitle (state, payload) {
      state.title = payload
    }
  },
  actions: {
  },
  modules: {
  }
})
